package org.study.tdengine.mybatisplus.boot.service;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.study.tdengine.mybatisplus.boot.mapper.WeatherMapper;
import org.study.tdengine.mybatisplus.boot.model.Weather;

import java.util.List;

/**
 * 参考 https://www.codenong.com/cs109499380
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2023年05月14日
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class WeatherService {
    private final WeatherMapper weatherMapper;

    public boolean init() {
        // 创建表
        weatherMapper.createTable("db", "weather");
        return true;
    }

    public int save(Weather weather) {
        return weatherMapper.insert(weather);
    }

    public int batchSave(List<Weather> weatherList) {
        return weatherMapper.batchInsert(weatherList);
    }

    public List<Weather> query(Long limit, Long offset) {
        return weatherMapper.select(limit, offset);
    }
}
